Imports Janus.Windows.TimeLine
Public Class frmHOTEL
    Dim FromDate As Date = Now.Date

    Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
        Dim frm As New frmRESERVATION_DETAIL
        frm.ShowDialog()
        Search()
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
        Application.Exit()
    End Sub
    Private Sub UpdateTimeLine()
        Dim hourduration As Integer
        hourduration = timeLine1.WorkEndTime.TotalHours - timeLine1.WorkStartTime.TotalHours
        If hourduration = 0 Then Return
        Dim Interval As Integer
        Interval = (Me.Width - timeLine1.RowHeaderWidth) * 3.6 / hourduration
        timeLine1.IntervalSize = Interval

        Dim MaxMyDate As DateTime = Date.Parse(CStr(FromDate.Month) & "/" & CStr(FromDate.Day) & "/" & CStr(FromDate.Year) & " 07:00:00.000")
        Dim FirstMyDate As DateTime = Date.Parse(CStr(FromDate.Month) & "/" & CStr(FromDate.Day) & "/" & CStr(FromDate.Year) & " 06:15:00.000")
        Me.timeLine1.FirstDate = FirstMyDate
        Me.timeLine1.MaxDate = MaxMyDate
    End Sub

    Private Sub frmQUICK_RESERVATION_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Try
            GC.Collect()
            Me.Dispose()
        Catch ex As Exception

        End Try
    End Sub
    Private Sub frmQUICK_RESERVATION_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        PublicFunction.NewFormLoad(Me)

        timeLine1.TextMember = "ItemName" '"TTime"
        Dim group_TblName As TimeLineGroup = New TimeLineGroup(Me.timeLine1.Fields("TBL_Code"))
        Me.timeLine1.Groups.Add(group_TblName)

        Me.timeLine1.WorkStartTime = System.TimeSpan.Parse(PublicVariable.WorkingStartTime)
        Me.timeLine1.WorkEndTime = System.TimeSpan.Parse(PublicVariable.WorkingEndTime)

        'Dim item As TimeLineItem = Me.timeLine1.Items(0)
        'item.ItemBarFomatStyle.BackColor = Color.Pink

        FromDate = PublicVariable.SystemDate
        Search()
    End Sub

    Private Sub GridFloor_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Search()
    End Sub

    Private Sub btnFrom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim frm As New frmCalendar
        frm.ShowDialog()
        FromDate = frm.Calendar2.SelectionRange.Start
        Search()
    End Sub

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
    Private Sub Search()
        'Dim dt As DataTable
        'dt = oReservation.Reservation_Search_TABLE(FromDate)

        Dim arName As New ArrayList
        arName.Add("@FL_CODE")
        arName.Add("@DATE")
        Dim arVal As New ArrayList
        arVal.Add("")
        arVal.Add(FromDate)

        timeLine1.DataSource = BLL.ObjectGetBy("RESERVATION_TABLES_LOADBYFLOOR", arName, arVal)
        UpdateTimeLine()
        UpdateTimeLine()
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Dim dr As DataRowView = CType(timeLine1.SelectedItems.Item(0).Item.DataRow, DataRowView)
        If dr.Item("ID") > 0 Then
            Dim arName As New ArrayList
            arName.Add("@ID")
            arName.Add("@USER")
            arName.Add("@STATUS")
            Dim arVal As New ArrayList
            arVal.Add(dr.Item("ID"))
            arVal.Add(PublicVariable.UserCode)
            arVal.Add(3)
            BLL.Object_Update_NonResult("RESERVATION_STATUS", arName, arVal)
        End If
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Dim dr As DataRowView = CType(timeLine1.SelectedItems.Item(0).Item.DataRow, DataRowView)
        If dr.Item("ID") > 0 Then
            Dim arName As New ArrayList
            arName.Add("@ID")
            arName.Add("@USER")
            arName.Add("@STATUS")
            Dim arVal As New ArrayList
            arVal.Add(dr.Item("ID"))
            arVal.Add(PublicVariable.UserCode)
            arVal.Add(4)
            BLL.Object_Update_NonResult("RESERVATION_STATUS", arName, arVal)
        End If
    End Sub

    Private Sub btnCheckIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheckIn.Click
        Dim dr As DataRowView = CType(timeLine1.SelectedItems.Item(0).Item.DataRow, DataRowView)
        If dr.Item("ID") > 0 Then
            Dim arName As New ArrayList
            arName.Add("@ID")
            arName.Add("@USER")
            arName.Add("@STATUS")
            Dim arVal As New ArrayList
            arVal.Add(dr.Item("ID"))
            arVal.Add(PublicVariable.UserCode)
            arVal.Add(2)
            BLL.Object_Update_NonResult("RESERVATION_STATUS", arName, arVal)

            'TODO: create bill with room rate item/ open order screen

        End If
    End Sub


    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
        If timeLine1.SelectedItems.Count = 0 Then Return
        Dim frm As New frmRESERVATION_DETAIL
        Dim dr As DataRowView = CType(timeLine1.SelectedItems.Item(0).Item.DataRow, DataRowView)
        If dr.Item("ID") > 0 Then
            frm.ID = dr.Item("ID")
            frm.ShowDialog()
            Search()

        End If

    End Sub

    Private Sub timeLine1_LastDateChanged(sender As System.Object, e As System.EventArgs) Handles timeLine1.LastDateChanged
        'timeLine1.FirstDate
    End Sub

    Private Sub pnHeader_Click(sender As System.Object, e As System.EventArgs) Handles pnHeader.Click

    End Sub
End Class